package bjut.zrpc.core.optimization.beanPostProcessor;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @Author: zhuzhiming
 * @Date: 2022/7/2 23:45
 */
@Component
public class ZRpcApplicationContextAware implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {

        if (ZRpcApplicationContextAware.applicationContext == null) {
            ZRpcApplicationContextAware.applicationContext = applicationContext;
        }

    }

    public static <T> Map<String, T> getBeansOfType(Class<T> requiredType) {
        return applicationContext.getBeansOfType(requiredType);
    }

}
